package edu.zqu.course.project.controller;


import edu.zqu.common.result.ZQUResult;
import edu.zqu.course.project.service.CourseService;
import edu.zqu.course.response.CourseNumAndName;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author 郭泽鹏
 * @since 2020-06-24
 */
@RestController
@RequestMapping("/course")
@Api(tags = "课程 前端控制器")
public class CourseController {
    @Resource
    private CourseService courseService;

    /**
     * 获取课程编号和课程名
     */
    @GetMapping("num_name/{id}")
    @ApiOperation(value = "查询课程编号和课程名")
    public ZQUResult getCourseNumAndName(@PathVariable(value = "id") String id){
        CourseNumAndName courseNumAndName = courseService.getCourseNumAndName(id);
        return ZQUResult.success("查询成功", courseNumAndName);
    }

    /**
     * 删除操作
     */
    @DeleteMapping("/{id}")
    @ApiOperation(value = "通过课程id进行删除")
    public ZQUResult deleteByCId(@PathVariable(value = "id") Long id){
        Integer result = courseService.deleteByCId(id);
        return ZQUResult.success("删除成功", result);
    }
}

